<?php
/**
 * Handles the view functionality of our MVC Framework
 */
class View_Core {
	/**
	 * Holds variables assigned to template
	 */
	private $render = FALSE;
	/**
	 * Accept a template to load
	 */
	public function __construct($template){
		// compose file name
		$file = SERVER_ROOT . '/' . basename('views') . '/' . basename(strtolower($template) . '.php');
		if(file_exists($file)) {
			/**
			 * trigger render to include file when this model is destroyed
			 * if we render it now, we wouldn't be able to assign variables
			 */
			$this->render = $file;
		}
	}
	
	/**
	 * Receives assigments from controller and stores in local data array
	 * 
	 * @param $variable
	 * @param $value
	 */
	public function assign($variable, $value){
		$this->data[$variable] = $value;
	}
	
	public function __destruct(){
		// parse data variables, so that they render to the view
		$data = $this->data;
		// render view
		include($this->render);
	}
}